/**
 * Created by Administrator on 2016/6/29 0029.
 */
$(document).ready(function () {
    content_left();
    content_right();
    mouse_btn();
});

function mouse_btn() {
    var mouse_obj = $(".top-mouse-div");
    mouse_obj.each(function (index) {
        $(this).click(function () {
            var obj = "";
            var obj_next = "";
            var num;
            mouse_obj.unbind("click");
            $(".right-news").each(function (i) {
                if (i + 1 == index) {
                    obj_next = $(this);
                }
                if ($(this).css("display") == "block") {
                    obj = $(this);
                    num = i + 1;
                }
            });
            if (obj_next != "" && obj != "" && num != index) {
                mouse_btn_animate(obj, obj_next)
            } else {
                mouse_btn();
            }
        })
    })
}

function mouse_btn_animate(obj, obj_next) {
    obj.animate({
        "opacity": "0"
    }, 400, function () {
        obj.css("display", "none")
    });
    obj_next.css({"opacity": "0", "display": "block"}).animate({
        "opacity": "1"
    }, 400, function () {
        mouse_btn();
    })
}

function content_left() {
    var obj = $(".top-mouse-div");
    obj.each(function (index) {
        var mouse_div = $(this);
        mouse_div.mouseover(function () {
            var red_div;
            if (mouse_div.next().height() > 0) {
                obj.unbind("mouseover");
                $(".left-bottom-words").each(function (i) {
                    if (i == index) {
                        $(this).css({"display": "block", "opacity": "0"}).animate({"opacity": "1"}, 300);
                    } else {
                        $(this).css({"display": "none"});
                    }
                });
                obj.each(function () {
                    $(this).parent().css({
                        "transform": "scale(0.89)",
                        "-ms-transform": "scale(0.89)",
                        "-moz-transform": "scale(0.89)",
                        "-webkit-transform": "scale(0.89)",
                        "-o-transform": "scale(0.89)"
                    });
                    if ($(this).next().next().height() > 0) {
                        red_div = $(this);
                    }
                });
                top_div(mouse_div);
                red_div.next().next().css("height", "0");
                red_div.next().css({"height": "184px", "z-index": "1"});
                mouse_div.next().next().css("z-index", "2").animate({"height": "184px"}, 300, function () {
                    mouse_div.next().css("height", "0");
                    mouse_div.next().next().css("z-index", "1");
                    content_left();
                });
            }
        });
    });
}
function top_div(mouse_div){
    clearInterval(time);
    var i = 89;
    var time = setInterval(function(){
        i = i+1;
        mouse_div.parent().css({
            "transform": "scale("+(i/100)+")",
            "-ms-transform": "scale("+(i/100)+")",
            "-moz-transform": "scale("+(i/100)+")",
            "-webkit-transform": "scale("+(i/100)+")",
            "-o-transform": "scale("+(i/100)+")"
        });
        if(i>=100){
            clearInterval(time);
        }
    },14);
}
function content_right() {
    var obj = $(".banner-img");
    var banner_time;

    function right_initialization() {
        for (var i = 0; i < obj.size(); i++) {
            $(".banner-spot").append("<div></div>")
        }
        obj.each(function (index) {
            if (index == 0) {
                $(this).css("display", "block");
            } else {
                $(this).css("display", "none");
            }
        });
        $(".banner-spot").find("div").each(function (index) {
            if (index == 0) {
                $(this).css("background-color", "#e1515b")
            }
        });
        right_banner();
        right_spot();
    }

    function right_banner() {
        var num;
        var eve;
        var x = 0;
        banner_time = setInterval(function () {
            x++;
            obj.each(function (index) {
                if ($(this).css("display") == "block") {
                    if (index == obj.size() - 1) {
                        num = 0;
                    } else {
                        num = index + 1;
                    }
                    eve = $(this);
                }
                if (index == num && num < obj.size()) {
                    $(this).css({"left": "460px", "display": "block"});
                    var temporary_time = setTimeout(function () {
                        $(".banner-spot").find("div").each(function (x) {
                            if (x == num) {
                                $(this).css("background-color", "#e1515b")
                            } else {
                                $(this).css("background-color", "#fff");
                            }
                        })
                    }, 300);
                    eve.animate({"left": "-460px"}, 400);
                    $(this).animate({"left": "0"}, 400, function () {
                        eve.css({"display": "none", "left": "0"})
                    });
                }
            });
        }, 3000);
    }

    function right_spot() {
        var spot = $(".banner-spot").find("div");
        spot.each(function (index) {
            var spot_this = $(this);
            spot_this.click(function () {
                clearInterval(banner_time);
                spot.each(function () {
                    $(this).css("background-color", "#fff");
                });
                spot_this.css("background-color", "#e1515b");
                obj.each(function (i) {
                    if (i == index) {
                        $(this).css({
                            "opacity": "0",
                            "display": "block",
                            "left": "0"
                        }).animate({"opacity": "1"}, 300, function () {
                            right_banner();
                        });
                    } else {
                        $(this).css("display", "none")
                    }
                })
            });
        });
    }

    right_initialization();
}